//设置cookie
function setCookie(name, val, timeS) {
    let d = new Date();
    d.setTime(d.getTime() + ( timeS* 1000));
    let expires = "expires=" + d.toUTCString();
    document.cookie = name + "=" + val + "; " + expires;
}

// 获取cookie
function getCookie(name) {
    let val = "";
    let cname = name + "=";
    let ca = document.cookie.split(';');
    for (let i = 0; i < ca.length; i++) {
        let c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(cname) != -1) {
            val = c.substring(cname.length, c.length);
        }
    }
    return val;
}

// 清空cookie
function  clearCookie(name) {
    setCookie(name, "", -1);
}